package com.iias.common.util.date;

import java.util.Date;

/**
 * 时间计算
 */
public class TimeCalculate {

    /**
     * 计算时间 +,-
     * @param date
     * @param format
     * @param val
     * @param timeUnit
     * @return
     */
    public static String cal(String date,String format,int val,TimeUnit timeUnit){
        return DateUtils.format(cal(DateUtils.format(date,format),val,timeUnit),format);
    }


    /**
     * 计算时间 + ,-
     * @param date
     * @param val
     * @param timeUnit
     * @return
     */
    public static Date cal(Date date,int val,TimeUnit timeUnit){
        DateProperty dateProperty = new DateProperty(date);
        int value = dateProperty.getField(timeUnit);
        dateProperty.setField(timeUnit,value+val);
        return dateProperty.getDate();
    }


    /**
     * 设置字段值
     * @param date
     * @param val
     * @param timeUnit
     * @return
     */
    public static Date setField(Date date,int val,TimeUnit timeUnit){
        DateProperty dateProperty = new DateProperty(date);
        dateProperty.setField(timeUnit,val);
        return dateProperty.getDate();
    }


}
